<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="槽号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="slotId">
              <a-input v-model="model.slotId" placeholder="请输入槽号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="记录时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recorddate">
              <j-date placeholder="请选择记录时间" v-model="model.recorddate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="槽电流" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="electric">
              <a-input v-model="model.electric" placeholder="请输入槽电流"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="槽电压" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="volt">
              <a-input v-model="model.volt" placeholder="请输入槽电压"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="槽电阻" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="resistance">
              <a-input v-model="model.resistance" placeholder="请输入槽电阻"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="滤波电阻" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="filterRes">
              <a-input v-model="model.filterRes" placeholder="请输入滤波电阻"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="平滑电阻" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="smoothRes">
              <a-input v-model="model.smoothRes" placeholder="请输入平滑电阻"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电阻针震值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="vibration">
              <a-input v-model="model.vibration" placeholder="请输入电阻针震值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电阻摆动值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="swing">
              <a-input v-model="model.swing" placeholder="请输入电阻摆动值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电阻斜率mv" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="slope">
              <a-input v-model="model.slope" placeholder="请输入电阻斜率mv"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电阻累斜" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accsloper">
              <a-input v-model="model.accsloper" placeholder="请输入电阻累斜"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际下料间隔时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realNbInterval">
              <a-input-number v-model="model.realNbInterval" placeholder="请输入实际下料间隔时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态：1阳升2阳降3手动阳升4手动阳降 参照运行状态1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="poleUpDown">
              <a-input-number v-model="model.poleUpDown" placeholder="请输入状态：1阳升2阳降3手动阳升4手动阳降 参照运行状态1" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态: 1有0 无 参照 面板状态1 并且电压>8V" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reaction">
              <a-input-number v-model="model.reaction" placeholder="请输入状态: 1有0 无 参照 面板状态1 并且电压>8V" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态: 1有 0 无 面板状态2 出铝" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outAl">
              <a-input-number v-model="model.outAl" placeholder="请输入状态: 1有 0 无 面板状态2 出铝" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态: 1有 0无 面板状态4 换极" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changePole">
              <a-input-number v-model="model.changePole" placeholder="请输入状态: 1有 0无 面板状态4 换极" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态: 1有 0无 面板状态4 边加工" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sideProcess">
              <a-input-number v-model="model.sideProcess" placeholder="请输入状态: 1有 0无 面板状态4 边加工" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="纯手动操作状态: 1有0无 故障状态1 纯手动" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pureManOperation">
              <a-input-number v-model="model.pureManOperation" placeholder="请输入纯手动操作状态: 1有0无 故障状态1 纯手动" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下料状态 0 無 1自動小下料 2自動大下料 3 手動小下料  4手動大下料 面板狀態2+開關狀態1 下料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankState">
              <a-input-number v-model="model.bankState" placeholder="请输入下料状态 0 無 1自動小下料 2自動大下料 3 手動小下料  4手動大下料 面板狀態2+開關狀態1 下料" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电压上限 //控制电压上限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="voltUpperLimit">
              <a-input v-model="model.voltUpperLimit" placeholder="请输入电压上限 //控制电压上限"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电压下限 //控制电压下限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="voltLowerLimit">
              <a-input v-model="model.voltLowerLimit" placeholder="请输入电压下限 //控制电压下限"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设定下料间隔" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="setNbInterval">
              <a-input-number v-model="model.setNbInterval" placeholder="请输入设定下料间隔" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="效应距今" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reactionInterval">
              <a-input-number v-model="model.reactionInterval" placeholder="请输入效应距今" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="母綫位移狀態 0無 1有" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="busPutUp">
              <a-input-number v-model="model.busPutUp" placeholder="请输入母綫位移狀態 0無 1有" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="氟盐狀態 0無 1手動氟盐 2自動氟盐" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fuSalt">
              <a-input-number v-model="model.fuSalt" placeholder="请输入氟盐狀態 0無 1手動氟盐 2自動氟盐" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前的设定电压值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="voltSet">
              <a-input v-model="model.voltSet" placeholder="请输入当前的设定电压值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下料模式  0 停料 1 正常下料 2 基本欠量周期 3长欠周期 4 基本过量周期 5 长过周期 6 效应处理下料 7 效应等待 10 定时下料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbMode">
              <a-input-number v-model="model.nbMode" placeholder="请输入下料模式  0 停料 1 正常下料 2 基本欠量周期 3长欠周期 4 基本过量周期 5 长过周期 6 效应处理下料 7 效应等待 10 定时下料" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="母线位移值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="poleMoveValue">
              <a-input-number v-model="model.poleMoveValue" placeholder="请输入母线位移值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="正常下料次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="normNbTimes">
              <a-input-number v-model="model.normNbTimes" placeholder="请输入正常下料次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="欠量下料次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oweNbTimes">
              <a-input-number v-model="model.oweNbTimes" placeholder="请输入欠量下料次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="过量下料次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="overNbTimes">
              <a-input-number v-model="model.overNbTimes" placeholder="请输入过量下料次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="阳极位移01" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="poleMove01">
              <a-input-number v-model="model.poleMove01" placeholder="请输入阳极位移01" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="阳极位移02" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="poleMove02">
              <a-input-number v-model="model.poleMove02" placeholder="请输入阳极位移02" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="取消阳移" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stopRc">
              <a-input-number v-model="model.stopRc" placeholder="请输入取消阳移" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'DataHistoryForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           slotId: [
              { required: true, message: '请输入槽号!'},
           ],
           recorddate: [
              { required: true, message: '请输入记录时间!'},
           ],
        },
        url: {
          add: "/dataHistory/dataHistory/add",
          edit: "/dataHistory/dataHistory/edit",
          queryById: "/dataHistory/dataHistory/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>